package net.sxnic.workflow.node.action;

import net.sxinfo.core.dao.Page;
import net.sxinfo.core.dao.hibernate3.HibernateCriteria;
import net.sxinfo.core.util.WebUtils;
import net.sxnic.workflow.pd.Pd;
import net.sxnic.workflow.pd.PdManager;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;

@SuppressWarnings("serial")
public class Browse extends NodeAction {
	
	private String pdId;
	
	private Page datas;
	
	@Autowired
	private PdManager pdManager;

	public String execute() throws Exception {
		
		int pageNumber = WebUtils.getPageNumber(request);
		int pageSize = WebUtils.getPageSize(request);
		
		if(StringUtils.isBlank(pdId)){
			datas = nodeManager.getPage(pageNumber, pageSize, "pd", true);
		}else{
			Pd pd = pdManager.get(pdId);
			
			HibernateCriteria hc = new HibernateCriteria();
			
			Criterion dc = Restrictions.eq("pd", pd);
			
			hc.add(dc);
			
			datas = nodeManager.getPageByCriteria(pageNumber, pageSize, hc);			
		}
		
		
		return SUCCESS;
	}

	public Page getDatas() {
		return datas;
	}

	public void setDatas(Page datas) {
		this.datas = datas;
	}

	public String getPdId() {
		return pdId;
	}

	public void setPdId(String pdId) {
		this.pdId = pdId;
	}
}
